﻿@model IEnumerable<Model.ViewModel.Goods>

@{
    Layout = null;

}

<div class="well well-sm">
    <span class="text-danger"> @ViewData["GoodsSortName"]</span>大类的管理：&nbsp;&nbsp;<button type="button" class="btn btn-warning" onclick="Open_ModifyGoodsSortName()">修改大类名字</button>&nbsp;&nbsp;<button type="button" class="btn btn-warning" onclick="Open_DeleGoodsSortName()">删除此大类</button>

    <button type="button" class="btn btn-warning" onclick="Open_myModal_AddGords()">为此大类添加具体商品</button>

</div>
<div class="table-responsive">
    <table class="table table-condensed">
        @{foreach (var g in Model)
        {

            <tbody>
                <tr>
                    <td>@g.GoodsName</td>
                    <td class="text-info">数量：<span class="badge">@g.Quntity</span></td>
                    <td><button type="button" class="btn btn-default btn-sm" onclick="Open_Model_UpGoods('@g.GoodsID', '@g.GoodsName','@g.Quntity')">上货</button></td>
                    <td>
                        <a class="Edit_Goods"
                           href="#?Quntity=@g.Quntity&GoodsID=@g.GoodsID&GoodsName=@g.GoodsName&MeasureUnite=@g.MeasureUnite&SalePrice=@g.SalePrice&PurchasePrice=@g.PurchasePrice&StockUnite=@g.StockUnite&StockQuntity=@g.StockQuntity&Multiple=@g.Multiple">更改</a>
                    </td>
                    <td>
                        <button type="button" class="btn btn-primary btn-xs" onclick="DeleteGoodsByID('@g.GoodsID','@g.GoodsName')">
                            删除
                        </button>
                    </td>
                </tr>
            </tbody>

        }

        }
    </table>
</div>

@Html.Partial("AdminAddGoods", this.ViewData)
@Html.Partial("EditGoods")
@Html.Partial("ModifyGoodsSortName", this.ViewData)
@Html.Partial("Confirm")
@Html.Partial("ConfirmDeleteGoodsSort")
@Html.Partial("Modal_UpGoods")

<script type="text/javascript">
    var GoodssID,GoodssName;
    //添加商品大类
    function Open_myModal_AddGords() {

        $("#myModal_AddGords").modal('show');
    }
    //上货架
    function Open_Model_UpGoods(ID, Name, Q) {
        $("#myModal_UpGoods .modal-footer span").html('');
        $("#myModal_UpGoods .modal-header h4 span:last-child").html(Name);
        $("#myModal_UpGoods form input[name='GoodsID']").val(ID);
        $("#myModal_UpGoods .modal-header h5 span").html(Q);
        $("#myModal_UpGoods").modal('show');
    }
    function Open_ModifyGoodsSortName() {
        $("#myModal_ModifyGoodsSortName").modal('show');
    }
    //------------------------------------------------------------打开删除商品大类------------------------------------------
    function Open_DeleGoodsSortName() {
        $("#myModal_ConfirmDeleteGoodsSort .modal-body span").html('@ViewData["GoodsSortname"]');
        $("#myModal_ConfirmDeleteGoodsSort").modal('show');
    }
    //上架货物模态框关闭之后触发
    $("#myModal_UpGoods").on('hidden.bs.modal', function (e) {
        //刷新下拉框
        $("#GoodsSortList").load('Admin/AdminGoods');
        $("#Pannel_Goodslist").load('Admin/GoodssByTeamID/' + '@ViewData["GoodsSortID"]');
    });
    //删除模态框关闭之后触发
    $("#myModal_ConfirmDeleteGoodsSort").on('hidden.bs.modal', function (e) {
        //刷新下拉框
        $("#GoodsSortList").load('Admin/AdminGoods');
        $("#Pannel_Goodslist").load('Admin/GoodssByTeamID/' + '@ViewData["GoodsSortID"]');
    });
    $('#myModal_ConfirmDeleteGoodsSort').on('show.bs.modal', function (e) {

        $("#myModal_ConfirmDeleteGoodsSort .modal-footer>span").html("");
    })
    //具体执行操作删除
    $("#myModal_ConfirmDeleteGoodsSort .modal-footer .btn:last-child").on("click", function () {
        $.ajax({
            type: 'POST',
            data: "GoodsSortID=" + '@ViewData["GoodsSortID"]',

            url: 'Admin/btn_DeleteGoodsSort',
            success: function (data) {

                if (data == "ok") {
                    $("#Pannel_Goodslist .well").html("<s>@ViewData["GoodsSortName"]</s>大类已被删除成功！");
                    //把Well下那个删除的大类名字抹掉，增加用户体验

                    //增加添加成功信息

                    $("#myModal_ConfirmDeleteGoodsSort .modal-footer").find("span").show().html("删除成功！");
                    $("#myModal_ConfirmDeleteGoodsSort").modal('toggle');
                }
                else if (data == "Has") { $("#myModal_ConfirmDeleteGoodsSort .modal-footer").find("span").show().html("大类下不为空！不能删除"); }
                else { alert("删除失败！"); }

            },
            error: function (error) {
                alert(error.responseText);
            }
        });
    });
    //--------------------------------------------------------------删除商品大类结束--------------------------------------
    //打开删除这个商品
    function DeleteGoodsByID(GoodsID,GoodsName) {
       
      
        GoodssID = GoodsID;
        GoodssName = GoodsName;
        $("#myModal_Confirm .modal-body span").html(GoodsName);
        $("#myModal_Confirm").modal('show');
       
    }
    //删除模态框关闭之后触发
    $("#myModal_Confirm").on('hidden.bs.modal', function (e) {

        
        $("#Pannel_Goodslist").load('Admin/GoodssByTeamID/' + '@ViewData["GoodsSortID"]');
    });
    $('#myModal_Confirm').on('show.bs.modal', function (e) {

        $("#myModal_Confirm .modal-footer>span").html("");
    })
    //具体执行操作删除
    $("#myModal_Confirm .modal-footer .btn:last-child").on("click", function () {
        $.ajax({
            type: 'POST',
            data: "GoodsID=" + GoodssID,
              
            url: 'Admin/btn_DeleteGoods',
            success: function (data) {

                if (data == "ok") {
                    //$("#myModal_AddGords").modal("hide");
                    //刷新下拉菜单绑定的商品分类

                    //增加添加成功信息
                  
                    $("#myModal_Confirm .modal-footer").find("span").show().html("删除成功！");
                    $("#myModal_Confirm").modal('toggle');
                }
                else { alert("没有成功"); }

            },
            error: function (error) {
                alert(error.responseText);
            }
        });
    });
</script>
<script type="text/javascript">
    //获取Url?参数
    function GetRequest(url) {

        // var url = location.search; //获取url中"?"符后的字串
        // alert($(this).html());

        var theRequest = new Object();
        if (url.indexOf("?") != -1) {

            var str = url.substr(url.indexOf("?") + 1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }

        return theRequest;
    }

    $(".Edit_Goods").bind("click", function () {

        var Request = new Object();
        Request = GetRequest(this.toString());
        $("#myModal_EditGords form input[name='GoodsID']").val(Request['GoodsID']);
        $("#myModal_EditGords form input[name='GoodsName']").val(Request['GoodsName']);
        $("#myModal_EditGords form input[name='SalePrice']").val(Request['SalePrice']);
        $("#myModal_EditGords form input[name='Quntity']").val(Request['Quntity']);
        $("#myModal_EditGords form input[name='MeasureUnite']").val(Request['MeasureUnite']);
        $("#myModal_EditGords form input[name='StockUnite']").val(Request['StockUnite']);
        $("#myModal_EditGords form input[name='StockQuntity']").val(Request['StockQuntity']);
        $("#myModal_EditGords form input[name='Multiple']").val(Request['Multiple']);
        $("#myModal_EditGords form input[name='PurchasePrice']").val(Request['PurchasePrice']);
        $("#myModal_EditGords").modal('show');
    });


</script>

